package com.ysyx.ysyx_message.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ysyx.ysyx_message.dto.BaseDto;
import com.ysyx.ysyx_message.mapper.OrderPojoMapper;
import com.ysyx.ysyx_message.mapper.PassengerreviewPojoMapper;
import com.ysyx.ysyx_message.pojo.OrderPojo;
import com.ysyx.ysyx_message.pojo.PassengerreviewPojo;
import com.ysyx.ysyx_message.service.OrderPojoService;
import com.ysyx.ysyx_message.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:郭宇轩
 * @create:2023/4/19 9:56
 */
@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private PassengerreviewPojoMapper passengerreviewPojoMapper;

    @Autowired
    private OrderPojoMapper orderPojoMapper;

    @Override
    public BaseDto passengerReview(String orderId, Integer score) {

        System.out.println("当前订单号为="+orderId+",评价分数为="+score);
        QueryWrapper<OrderPojo> orderQw = new QueryWrapper<>();
        orderQw.eq("order_id",orderId);
        OrderPojo orderPojo = orderPojoMapper.selectOne(orderQw);
        PassengerreviewPojo passengerreviewPojo = new PassengerreviewPojo();

        if(orderPojo==null){
            return new BaseDto(200,"系统错误，请确认订单是否存在",null);
        }else if(score>5||score<1){
            return new BaseDto(300,"分数评价错误",null);
        } else{

            QueryWrapper<PassengerreviewPojo> passengerreviewQw = new QueryWrapper<>();
            passengerreviewQw.eq("order_id",orderId);

            PassengerreviewPojo tempPassengerreviewPojo = passengerreviewPojoMapper.selectOne(passengerreviewQw);
            if(tempPassengerreviewPojo==null){
                passengerreviewPojo.setPassengerId(orderPojo.getPassengerId());
                passengerreviewPojo.setReviewRating(score);
                passengerreviewPojo.setOrderId(orderId);
                return new BaseDto(100,"评价成功",null);
            }else{
                return new BaseDto(400,"评价已存在，请勿重复评价",null);
            }


        }
    }

    @Override
    public BaseDto driverReview(String orderId, Integer score) {
        return new BaseDto(score,orderId,null);
    }

    @Override
    public BaseDto passengerReviewList(Integer passengerId) {
        return new BaseDto(passengerId,null,null);
    }

    @Override
    public BaseDto driverReviewList(Integer driverId) {
        return new BaseDto(driverId,null,null);
    }

    @Override
    public BaseDto passengerCheckReview(String orderId) {
        return new BaseDto(0,orderId,null);
    }

    @Override
    public BaseDto driverCheckReview(String orderId) {
        return new BaseDto(0,orderId,null);
    }
}
